

local function SendGroupConfigs(ply, cmd, args)
	local tblConfigs = netadmin.Lib.GetAllConfigs()
	
	for i, v in pairs(tblConfigs) do
			tblConfigs[i] = netadmin.Lib.MakeStringTableSafe(v)
	end
	
	local strConfigs = ULib.makeKeyValues(tblConfigs)
	
	umsg.Start("netadminStartConfigs", ply)
	umsg.End()
	

	while strConfigs:len() > 0 do
		umsg.Start("netadminConfigs", ply)
			umsg.String(strConfigs:sub( 1, 230 ))
		umsg.End()
		strConfigs = strConfigs:sub( 231 )
	end

	umsg.Start("netadminEndConfigs", ply)
	umsg.End()
end

ULib.concommand("netadmin_configs", SendGroupConfigs, nil, ULib.ACCESS_ADMIN)
ULib.addSayCommand("!netConfigs", SendGroupConfigs, "netadmin_configs",nil,true)


--format netadmin_del_cfg <group> <id>
local function DelConfigEntry(ply, cmd, args)
	Msg("NETADMIN:Deleting from Group:" .. args[1] .. " ID:" .. args[2] .. "\n")
	gdatabase.Query("DELETE FROM `config` WHERE id = " .. args[2] .. ";", netadmin.DB)
end
concommand.Add("netadmin_del_cfg", DelConfigEntry)

--format netadmin_add_cfg <group> <config setting>
local function AddConfigEntry(ply, cmd, args)
	Msg("NETADMIN: Adding new config line to group:" .. args[1] .. "\n")
	args[2] = gdatabase.CleanString(netadmin.DB,netadmin.Lib.ReventQuotes(args[2]))
	gdatabase.Query("INSERT INTO `config` ( `group`, `data`) VALUES ( \'" .. args[1] .. "\', \'" .. args[2] .. "\');", netadmin.DB)
	
	umsg.Start("netadminFlushConfigBuffer", ply)
		umsg.String(netadmin.Lib.GetID(args[2]))
	umsg.End()
end
concommand.Add("netadmin_add_cfg", AddConfigEntry)

--format netadmin_mod_cfg <id> <config setting>
local function ModConfigEntry(ply, cmd, args)
	Msg("NETADMIN:Modifying Config ID:" .. args[1] .. "\n")
	gdatabase.Query("UPDATE `config` SET `data` =  \'" .. gdatabase.CleanString(netadmin.DB,netadmin.Lib.ReventQuotes(args[2])) .. "\' WHERE `id` = " .. args[1] .. ";" , netadmin.DB)
	
	umsg.Start("netadminFlushConfigBuffer", ply)
		umsg.String(args[1])
	umsg.End()
end
concommand.Add("netadmin_mod_cfg", ModConfigEntry)

--format netadmin_add_grp_cfg  <group>
local function AddGroup(ply, cmd, args)
	Msg("NETADMIN:Adding Group Named:" .. args[1] .. "\n")
	gdatabase.Query("INSERT INTO `config` ( `group`, `data`) VALUES ( \'" .. args[1] .. "\', \'PLACEHOLDER, PLEASE MODIFY\');", netadmin.DB)
end
concommand.Add("netadmin_add_grp_cfg", AddGroup)
